const mysql=require('mysql');

const db=mysql.createConnection({
        host:'localhost',
        user:'root',
        password:'root',
        database:'tiantianpeiwan'
});

let Tmodule={
    chat:function(id,fn){
        let sql=`SELECT ch_name,pw_id,U_falsename,U_photo FROM (SELECT ch_name,pw_id FROM p_chat WHERE ku_id=${id}) AS a JOIN p_user ON a.pw_id=U_id;`
        console.log(sql)
        db.query(sql,function(err,data){
            fn(err,data)
        })
    },
    pchat:function(id,fn){
        let sql=`SELECT ch_name,ku_id,U_falsename,U_photo FROM (SELECT ch_name,ku_id FROM p_chat WHERE pw_id=${id}) AS a JOIN p_user ON a.ku_id=U_id;`
        console.log(sql)
        db.query(sql,function(err,data){
            fn(err,data)
        })
    }
}


module.exports=Tmodule;